package com.nightpiter.view.drawer.dynamic;

import static com.nightpiter.view.drawer.dynamic.Config.*;
import static com.nightpiter.view.drawer.dynamic.Config.hubBackRadius;
import static com.nightpiter.view.drawer.dynamic.Config.hubRadius;
import static com.nightpiter.view.drawer.dynamic.Config.stationBackRadius;
import static com.nightpiter.view.drawer.dynamic.Config.stationRadius;

import java.util.ArrayList;
import java.util.HashMap;

import com.nightpiter.model.objects.Station;
import com.nightpiter.view.Calculator;
import com.nightpiter.view.graphics.Canvas;
import com.nightpiter.view.graphics.Color;
import com.nightpiter.view.graphics.Paint;
import com.nightpiter.view.graphics.PointF;
import com.nightpiter.view.graphics.abstaractions.AbstractPaint.Style;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * 
 */
abstract class Amoeba {

	protected AmoebaUltimate amoebaUltimate;

	protected IntermediateAmoeba intermediateAmoeba;

	protected Amoeba brotherAmoeba;

	protected HashMap<Amoeba, Bacillus> bacillusMap = new HashMap<Amoeba, Bacillus>();

	public Bacillus getBacillus(Amoeba amoeba) {
		return bacillusMap.get(amoeba);
	}

	void addNeighbor(Amoeba neighborAmoeba, Bacillus bacillus) {
		bacillusMap.put(neighborAmoeba, bacillus);
	}

	protected PointF coordF;

	protected int[] colors;

	protected PointF[] coords;

	protected Station[] stations;

	protected int size;

	protected PointF pointF = new PointF();

	protected static Paint simplePaint = new Paint();
	
	protected static Paint complexPaint = new Paint();

	protected static Paint backSimplePaint = new Paint();

	protected static Paint backComplexPaint = new Paint();

	protected static Paint lightSimplePaint = new Paint();
	
	protected static Paint lightComplexPaint = new Paint();
	
	protected static Paint labelPaint = new Paint();
	
	protected abstract void applyCalculator(Calculator calculator);

	protected abstract void addDrawnAmoebas(ArrayList<Amoeba> drawnAmoebas);

	protected abstract void draw(Canvas canvas);

	protected abstract void highlight(Canvas canvas, int highlightColor);

	protected void drawLabels(Canvas canvas) {
		if (!Config.drawLabels) {
			return;
		}
		for (int i = 0; i < stations.length; i++) {
			Station station = stations[i];
			if (station.isLabelVisible()) {
				canvas.drawText(station.getName(), pointF.x
						+ station.getLabelX(), pointF.y + station.getLabelY(),
						labelPaint);
			}
		}
	}

	public static void setup() {
		simplePaint.setStrokeWidth(stationRadius * 2);
		complexPaint.setStrokeWidth(hubRadius);
		
		backSimplePaint.setStrokeWidth(stationBackRadius * 2);
		backComplexPaint.setStrokeWidth(hubBackRadius * 2);
		
		lightSimplePaint.setStrokeWidth(stationLightRadius * 2);
		lightComplexPaint.setStrokeWidth(hubLightRadius * 2);
		
		labelPaint.setTextSize(fontSize);
	}

	static {

		complexPaint.setAntiAlias(true);
		complexPaint.setStrokeCap(Paint.Cap.BUTT);
		complexPaint.setStyle(Style.FILL_AND_STROKE);
		
		simplePaint.setAntiAlias(true);
		simplePaint.setStrokeCap(Paint.Cap.ROUND);

		backComplexPaint.setAntiAlias(true);
		backComplexPaint.setStrokeCap(Paint.Cap.ROUND);
		backComplexPaint.setColor(Color.LTGRAY);

		backSimplePaint.setAntiAlias(true);
		backSimplePaint.setStrokeCap(Paint.Cap.ROUND);
		backSimplePaint.setColor(Color.LTGRAY);

		lightComplexPaint.setAntiAlias(true);
		lightComplexPaint.setStrokeCap(Paint.Cap.ROUND);

		lightSimplePaint.setAntiAlias(true);
		lightSimplePaint.setStrokeCap(Paint.Cap.ROUND);

		labelPaint.setAntiAlias(true);
		labelPaint.setColor(Color.DKGRAY);

	}

}
